package edu.sctu.zhuyingzhi.month201506.day20150608.timerV1;

import java.util.Scanner;

/**
 * Created by user13 on 2015/6/7.
 */
public class Timer implements Runnable{
    int i;
    private boolean j = true;
    Start start1 = new Start();
    Read read = new Read();
    Pause pause = new Pause();
    Stop stop = new Stop();


    public Timer(){
        System.out.println("------------------这是一个计时器--------------------");

    }


    public void startTimer(){
        Thread thread = new Thread(start1);
        thread.start();
    }

    public void stopTimer(){
        stop.run();
    }

    public void readTime(){

        read.getStart(start1);
        read.run();
    }

    public void pauseTimer(){


        Thread thread1 = new Thread(pause);
        pause.setTread(thread1,start1);
        pause.start1();
    }

    public void setJ(boolean j) {
        this.j = j;
    }

    @Override
    public void run() {
        System.out.println("请输入1开始计时");
        System.out.println("请输入2暂停计时");
        System.out.println("请输入3记录时间");
        System.out.println("请输入4退出计时");

        int x;
        Scanner in = new Scanner(System.in);
        while(j) {
             x = Integer.parseInt(in.next());
            switch (x) {
                case 1:
                    start1.setJudge(true);
                    startTimer();

                    break;
                case 2:
                    pauseTimer();
                    break;
                case 3:
                    readTime();
                    break;
                case 4:
                    stopTimer();
                    break;
            }
        }
    }
}
